﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblDowloadDAO
    {
        private DBService _db = null;

        public TblDowloadDAO(String connectionString)
        {
            _db = new DBService(connectionString);
        }
        public DataTable InsDowload(TblDowload tbldowload, int mode)
        {
            DataTable flag = null;
            try
            {
                flag = _db.ExeSP_DataTable("sp_tblDowload_InsUp",
                    new string[] { "@ID", "@NameFile", "@URLDowload", "@Mode" },
                    new object[] { tbldowload.ID, tbldowload.NameFile, tbldowload.URLDowload, mode }, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }

        public DataTable GetDSdowload()
        {
            DataTable Menu = null;
            try
            {
                Menu = _db.ExeSP_DataTable("select * from TblDowload", false, CommandType.Text);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return Menu;
        }

        public TblDowload GetDowloadById(int ID)
        {
            TblDowload dowload = new TblDowload();
            try
            {
                DataTable dt = null;
                dt = _db.ExeSP_DataTable("select * from TblDowload where ID = @ID",
                    new string[] { "@ID" },
                    new object[] { ID }
                        , CommandType.Text);
                foreach (DataRow dr in dt.Rows)
                {
                    dowload.ID = ID;
                    dowload.NameFile = dr["NameFile"].ToString();
                    dowload.URLDowload = dr["URLDowload"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dowload;
        }

        public bool DeleteDowLoad(TblDowload dowload)
        {
            bool flag = false;
            try
            {
                _db.ExeSP_NonQuery("delete TblDowload where ID = @ID",
                    new string[] { "@ID" },
                    new object[] { dowload.ID },
                    CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }
    }
}
